import confirmComponent from './index.vue'
import { h, render } from 'vue'
/**
 *
 * @param {*} title
 * @param {*} content
 * @param {*} cancelText
 * @param {*} confirmText
 */
export const confirm = (title, content, cancelText, confirmText) => {
  return new Promise((resolve, reject) => {
    if (title && !content) {
      content = title
      title = ''
    }
    // 关闭回调
    const close = () => {
      render(null, document.body)
    }
    // 成功回调
    const confirmHandle = () => {
      resolve()
    }
    // 失败回调
    const cancelHandle = () => {
      reject(new Error('取消按钮点击'))
    }
    // 生成虚拟节点
    const vNode = h(confirmComponent, {
      title,
      content,
      cancelText,
      confirmText,
      close,
      confirmHandle,
      cancelHandle
    })
    // 渲染虚拟节点
    render(vNode, document.body)
  })
}
